<?php

namespace IDock\Insurance\DAJIA\Request;

use IDock\Insurance\DAJIA\Bean\BusinessInfo;
use IDock\Insurance\DAJIA\Bean\CheckInfo;
use IDock\Insurance\DAJIA\Request\AllDAJIARequest;
use IDock\Insurance\DAJIA\Response\CommonResponse;
use IDock\Insurance\DAJIA\Response\InsuranceConfirmResponse;
use IDock\Insurance\DAJIA\Response\InsuranceOrderQueryResponse;
use IDock\Visitor\Premium\PremiumInquiryVisitor;
use IDock\Visitor\SpecialClausesVisitor;

/**
 * 查询保单接口
 */
class InsuranceConfirmRequest extends AllDAJIARequest
{
    protected $code = 'ODR1010';

    protected $response = InsuranceConfirmResponse::class;

    protected $urlTip = '核保接口';

    /**
     * @var PremiumInquiryVisitor $visitor
     */
    protected $visitor;

    public function generate(): array
    {
        $undrOpn = $this->visitor->getExtInfoVisitor()->underwriteMsg;

        if ($undrOpn) {
            $undrOpn = mb_substr($undrOpn,0,300);
        } else {
            $undrOpn = '无意见';
        }

        $data =  [
            'orderNo' => $this->visitor->getExtInfoVisitor()->argc['orderNo'] ?? '',
            'businessInfo' => $this->getBusinessInfo(),
            'checkInfo' => $this->getCheckInfo(),
            'undrOpn' => $undrOpn,
            'disputeResolution' => '007001',
            'arbitralCommitteeName' => '',
            'jqSpecialEngageList' => $this->getJqSpecialEngageList(),
            'sySpecialEngageList' => $this->getSySpecialEngageList(),
        ];

        return $data;
    }

    public function getBusinessInfo()
    {
        $extInfo = $this->visitor->getExtInfoVisitor();
        $busiId = $extInfo->argc['busiId'] ?? '';
        return [
            "busiId" => $busiId,
            "busiOpdpt" => $extInfo->argc['busiOpdpt'] ?? '',
            "busiDptCde" => $extInfo->argc['busiDptCde'] ?? '',
            "busiBrkrCde" => $extInfo->argc['busiBrkrCde'] ?? '',
            "busiAgentNme" => "",
            "busiGrantDptCde" => "",
            "busiGrantDptNme" => "",
            "busiOprCde" => $extInfo->argc['busiOprCde'] ?? '',
            "busiOprNme" => "",
            "busiBsnsTyp" => $extInfo->argc['busiBsnsTyp'] ?? '',
            "busiSlsId" => "",
            "busiSlsCde" => $extInfo->argc['busiSlsCde'] ?? '',
            "busiChaSalesId" => "",
            "busiSlsNme" => "",
            "busiRecommendCde" => $extInfo->argc['busiRecommendCde'] ?? '',
            "busiRecSubChannel" =>  $extInfo->argc['busiRecSubChannel'] ?? '',
            "busiCoopCde" => "",
            "busiCoopNme" => "",
            "busiRepairFlag" => "0",
            "busiGarageCode" => "",
            "busiGarageName" => "",
            "busiServiceCode" => "",
            "busiChannelSrc" => $extInfo->argc['busiChannelSrc'] ?? '',
            "busiDataSrc" => $extInfo->argc['busiDataSrc'] ?? '',
            "busiDataFlag" => $extInfo->argc['busiDataFlag'] ?? ''
        ];
    }

    public function getCheckInfo()
    {
        $vehicleInfo = $this->visitor->getVehicleVisitor();
        return [
            "vehiclePlateNo" => $vehicleInfo->licenseNo,
            "vehicleFrmNo" => $vehicleInfo->vin,
            "applicantNme" => $this->visitor->getApplicantVisitor()->name,
            "applicantCCertfCde" => $this->visitor->getApplicantVisitor()->certificateNo,
            "applicantMobile" => $this->visitor->getApplicantVisitor()->mobile,
            "insuredNme" => $this->visitor->getInsuredVisitor()->name,
            "insuredCertfCde" => $this->visitor->getInsuredVisitor()->certificateNo,
            "insuredMobile" => $this->visitor->getInsuredVisitor()->mobile
        ];
    }

    public function getJqSpecialEngageList()
    {
        $list = $this->visitor->getUnderwritingVisitor()->specialClausesList;
        $jqList = [];
        /**@var SpecialClausesVisitor $val**/
        foreach ($list as $val){
            if($val->riskType == 'TCI'){
                $jqList[] = [
                    'specialClausesCode' => $val->clauseCode,
                    'specialClausesContent' => $val->clauseContent,
                ];
            }
        }
        return array_values($jqList);
//        return [
//            ['specialClausesCode' => '07999999', 'specialClausesContent' => '标的车辆投保时，验车车身以下部位存在明显损伤：樊鑫（详见验车照片），在投保人或被保险人修理好前述车身损伤并提供合格验车照片由保险人进行批改后再出险，前述部位的损失方可纳入保险责任范围内。'],
//            ['specialClausesCode' => '07010320', 'specialClausesContent' => '行驶证车主为樊鑫，该车实际归樊鑫所有，归樊鑫使用。'],
//            ['specialClausesCode' => '07020320', 'specialClausesContent' => '其车险相关信息将由本公司共享至四川省保险行业协会，用于（且仅用于）行业与交管等政府部门进行信息共享，用于风险防范、社会管理等目的。'],
////            ['specialClausesCode' => '07060320', 'specialClausesContent' => '本保单进行保费实收后即时开始生效，保险止期相应提前。'],
//            ['specialClausesCode' => '0788880320', 'specialClausesContent' => '本保单的投保人为樊鑫，车主为樊鑫。'],
//            ['specialClausesCode' => '07030320', 'specialClausesContent' => '本保单的投保人为樊鑫，车主为樊鑫。'],
//            ['specialClausesCode' => '07980320', 'specialClausesContent' => '本保单的投保人为樊鑫，车主为樊鑫。'],
//            ['specialClausesCode' => '07080320', 'specialClausesContent' => '行驶证载明车型为小型客车。'],
//        ];
    }

    public function getSySpecialEngageList()
    {
        $list = $this->visitor->getUnderwritingVisitor()->specialClausesList;
        $biList = [];
        /**@var SpecialClausesVisitor $val**/
        foreach ($list as $val){
            if($val->riskType == 'VCI'){
                $biList[] = [
                    'specialClausesCode' => $val->clauseCode,
                    'specialClausesContent' => $val->clauseContent,
                ];
            }
        }
        return array_values($biList);
//        return [
//            ['specialClausesCode' => 'TY-002', 'specialClausesContent' => '此车按非营业投保。如用于营业，发生保险事故，保险人不承担赔偿责任。'],
//            ['specialClausesCode' => '07930356', 'specialClausesContent' => '发生保险事故时被保险机动车行驶证、号牌被注销的，保险公司不负责赔偿。'],
//            ['specialClausesCode' => '07090326', 'specialClausesContent' => '行驶证车主为樊鑫，该车实际归樊鑫所有，归樊鑫使用。'],
////            ['specialClausesCode' => '07999999', 'specialClausesContent' => '标的车辆投保时，验车车身以下部位存在明显损伤：樊鑫（详见验车照片），在投保人或被保险人修理好前述车身损伤并提供合格验车照片由保险人进行批改后再出险，前述部位的损失方可纳入保险责任范围内。'],
//            ['specialClausesCode' => '07010356', 'specialClausesContent' => '其车险相关信息将由本公司共享至四川省保险行业协会，用于（且仅用于）行业与交管等政府部门进行信息共享，用于风险防范、社会管理等目的。'],
//            ['specialClausesCode' => '07150356', 'specialClausesContent' => '经双方约定，投保人自愿投保修理期间费用补偿险。若发生保险事故，致使被保险机动车停驶，按照保险合同约定，在保险金额范围内，被保险人需返回保险人授权的本品牌专营店维修，且依据租赁汽车发票向保险人索赔补偿修理期间代步车费用。'],
//            ['specialClausesCode' => '07190356', 'specialClausesContent' => '此车按非营业投保。如用于营业，发生保险事故，保险人不承担赔偿责任。'],
//            ['specialClausesCode' => '0788880356', 'specialClausesContent' => '本保单的投保人为樊鑫，车主为樊鑫。'],
//            ['specialClausesCode' => '07760356', 'specialClausesContent' => '因电池组使用过程中的电池故障及异常，造成电池组自身及本车电器原件的损坏，不属于保险责任。'],
//        ];
    }

}
